package com.neo.design.chain.payment;

import com.neo.design.chain.ChainHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * 银行卡支付处理
 *
 * @author Kevin
 */
@Order(3)
@Component
@Slf4j
public class UnionPayHandler implements PaymentHandler {
    private ChainHandler<PaymentRequest, PaymentResult> next;

    @Override
    public PaymentResult handleRequest(PaymentRequest request) {
        if (request.getType() == PaymentRequest.PaymentType.UNION_PAY.getCode()) {
            return PaymentResult.builder().message("银联支付成功").build();
        }
        log.info("银联已经支付过了，有请其他支付");
        Assert.notNull(next, "支付已经完成，或不支持该操作。");
        return next.handleRequest(request);
    }

    @Override
    public void setNext(ChainHandler<PaymentRequest, PaymentResult> next) {
        this.next = next;
    }
}
